package com.ustb.controller;

import com.ustb.entity.PageResult;
import com.ustb.entity.Result;
import com.ustb.pojo.User;
import com.ustb.service.UserService;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
@RestController
@RequestMapping("/api/user")
//@CrossOrigin("*")  跨域(需要的时候添加)
public class UserController {

    @Resource
    private UserService userService;

    /**
     * 用户登录
     * @param user
     * @return
     */
    @RequestMapping("/login")
    //@CrossOrigin("*")
    public Result login(@RequestBody User user){
        return userService.login(user);
    }

    /**
     * 用户注册
     * @param user
     * @return
     */
    @RequestMapping("/reg")
    //@CrossOrigin("*")
    public Result reg(@RequestBody User user){
        return userService.reg(user);
    }

    /**
     * 根据id查询信息
     * @param id
     * @return
     */
    @RequestMapping("/findbyid")
    //@CrossOrigin("*")
    public Result findById(Integer id){
        return userService.findUserById(id);
    }

}